/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.entitygen;

import com.inspur.edp.caf.generator.BaseGenerator;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.field.FieldGenerator;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.api.dataType.valueObj.ICefValueObject;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.field.ResourceInfoFieldGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.method.DataTypeCtorGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.method.GetResInfoGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.method.GetResInfoInstanceGenerator;
import java.util.ArrayList;

public abstract class ValueObjectImplGenerator extends DataTypeImpGenerator {

  protected ValueObjectImplGenerator(EntityGeneratorContext parContext, IGspCommonDataType node) {
    super(parContext, node);
  }

  @Override
  protected void addExtendParentInterfaces(java.util.ArrayList<TypeInfo> parents) {
    parents.add(new TypeInfo(ICefValueObject.class.getTypeName()));
    addValueExtendParentInterfaces(parents);
  }

  protected abstract void addValueExtendParentInterfaces(java.util.ArrayList<TypeInfo> parents);

  @Override
  protected ClassMethodGenerator getConstructorGenerator(String typeName, String dataName) {
    return new DataTypeCtorGenerator(typeName, dataName);
  }

  @Override
  protected ArrayList<FieldGenerator> createFieldGenerator() {
    ArrayList<FieldGenerator> fieldGenerators=super.createFieldGenerator();
    if(fieldGenerators==null)
      fieldGenerators=new ArrayList<>();
    fieldGenerators.add(getResourceInfoFieldGenerator());
    return fieldGenerators;
  }

  protected ResourceInfoFieldGenerator getResourceInfoFieldGenerator() {
    return new ResourceInfoFieldGenerator(resInfoName,ParentContext);
  }

  protected final static String resInfoName = "entityResInfo";

  @Override
  protected ArrayList<BaseGenerator> createClassExtendChildGenrators() {
    ArrayList<BaseGenerator>  list = super.createClassExtendChildGenrators();
  if(list ==null)
    list =new ArrayList<>();
    list.add(getResouceInfoMethodGenerator());
    list.add(new GetResInfoInstanceGenerator(dataType));
    return list;
  }

  protected GetResInfoGenerator getResouceInfoMethodGenerator() {
    return new GetResInfoGenerator(resInfoName, dataType, ParentContext);
  }


  @Override
  protected void afterGenerate() {
    super.afterGenerate();
//    ParentContext.getProjContext().setMainDataType(new MediateType(getName(), ""));
  }
}
